import type {configInterface} from "./types/index"
import axios from "axios"
import {getToken} from "@/utils/storage";

const request = (config:configInterface)=>{
    const instance = axios.create({
        baseURL:"./",
        timeout:100000,
    })

    if(!config.headers){
        config.headers={
            "Content-Type": "application/json"
        }
    }

    let Token = getToken();
    if (Token) {
        config.headers = {
            ...config.headers,
            'X-CSRF-TOKEN': `VueCms_xg ${Token}`,
            'Authorization': `Bearer vuecms.cn`,
        }
    }

    instance.interceptors.request.use(config=>{
        return config
    },err=>{
        console.log("请求拦截的报错信息",err);
    })

    instance.interceptors.request.use(val=>{
        return val;
    },err=>{
        console.log("响应拦截的报错信息", err);
    })

    return instance(config)
}

export {request}